﻿using System.Windows.Forms;
using ReportWizard.Helpers;
using ReportWizard.Properties;

namespace ReportWizard.Forms
{
    public partial class SetFileNameForm : IconForm
    {
        public string NewName
        {
            get { return tbNewName.Text.Trim(); }
        }

        public string FormCaption
        {
            get { return HeaderText; }
            set { HeaderText = value; }
        }

        public bool IsNameRequired { get; set; }

        public SetFileNameForm(bool isNameRequired)
        {
            InitializeComponent();
            
            IsNameRequired = isNameRequired;

            ShowCustomLeftButton = false;
            ShowCustomRightButton = false;
            ShowCheckFooter = false;
        }

        private bool ValidateForm()
        {
            if (IsNameRequired)
            {
                if (string.IsNullOrEmpty(tbNewName.Text.Trim()))
                {
                    return false;
                }
                return true;
            }
            return true;
        }

        private void SetFileNameFormClickOk(object sender, System.EventArgs e)
        {
            if (ValidateForm())
            {
                DialogResult = DialogResult.OK;
            }
            else
            {
                ShowMessage.Error(Resources.SetName);
            }
        }

        private void SetFileNameFormClickCancel(object sender, System.EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}
